<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: #ccc;
            font-size: 28px;
            color: red;
            line-height: 200px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div id="code"></div>
    <input type="text" name="" id="newCode">
    <input type="button" name="" id="validate" value="验证">
    <script>
        window.onload=function(){
            var code='';
            var codeDiv=document.getElementById('code');
            var newCodeInput=document.getElementById('newCode');
            var validate=document.getElementById('validate');
            validate.onclick=function(){
                var newCode=newCodeInput.value.toUpperCase();
                if(newCode===code){
                    window.location.href='https://www.dyql.com/yuan/81102-0-0.html';
                }else{
                    alert('啥 B，验证码都输不对.');
                    newCodeInput.value='';
                    code='';
                    creatCode();
                }
            }
            creatCode();
            function random(max,min){
                return Math.floor(Math.random()*(max-min)+min);
            }
            function creatCode(){
               
                var codelength=4;
                var randomCode=[0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E',
                'F','G','H','I','G','K','L','M','N','O','P','Q','R','S',
                'T','U','V','W','X','Y','Z'];
                for(var i=0;i<codelength;i++){
                    var index=random(0,36);
                    code+=randomCode[index];
                }
                // return code;
                codeDiv.innerHTML=code;
             
            }
        }
    </script>
</body>
</html>